'use strict';
var Schema = require('mongoose').Schema,
    Model = require('../../../Base/server/controllers/Model');

var modelField = {};
//条码
modelField.Barcode = {
    type: String,
    default: '',
    trim: true,
    Name: '条码',
    IsUnique: true,
    IsEmpty: false
};

//类型 0: 物料 1: 部件 2: 仓库 3: 容器 4: 设备 5: 人 6: 其他
modelField.BarcodeType = {
    type: Number,
    Name: '条码类型'
};

//当前状态 0: 未激活、1:已激活、2:已下线、3:已报废、4:已完工、5:芯片失效
//2016-10-25 增加 作废状态  --by lwd
modelField.Status = {
    type: Number,
    Name: '状态'
};

//实体ID
modelField.EntityID = {
    type: String,
    trim: true,
    Name: '实体ID'
};

//装配标识
modelField.IsAssembly = {
    type: Boolean,
    Name: '是否装配'
};
//装配关系
modelField.AssemblyRelation = {
    type: Schema.ObjectId,
    ref: 'AssemblyRelation',
    Name: '装配关系ID'
};

//外部条码
modelField.OutsideBarcode = {
    type: String,
    trim: true,
    Name: '外部条码'
};

//当前流水
modelField.BizRecord = {
    type: Schema.ObjectId,
    ref: 'BizRecord',
    Name: '当前流水ID'
};

//当前工序
modelField.Operation = {
    type: Schema.ObjectId,
    ref: 'Operation',
    Name: '工序ID'
};
//工序名称
modelField.OperationName = {
    type: String,
    trim: true,
    Name: '工序名称'
};

//当前作业
modelField.Work = {
    type: Schema.ObjectId,
    ref: 'Work',
    Name: '作业ID'
};
//作业名称
modelField.WorkName = {
    type: String,
    trim: true,
    Name: '作业名称'
};

//当前工位
modelField.WorkLocation = {
    type: Schema.ObjectId,
    ref: 'WorkLocation',
    Name: '作业名称'
};
//工位名称
modelField.WorkLocationName = {
    type: String,
    trim: true,
    Name: '作业名称'
};

//当前终端
modelField.Terminal = {
    type: Schema.ObjectId,
    ref: 'Terminal',
    Name: '作业名称'
};
//终端名称
modelField.TerminalName = {
    type: String,
    trim: true,
    Name: '作业名称'
};

//当前用户集合
modelField.Users = {
    type: [
        {
            type: Schema.ObjectId,
            ref: 'User'
        }
    ],
    Name: '用户集合'
};

//当前质检类型 0: 全检 1:巡检 2:首件质检
modelField.QCType = {
    type: Number,
    Name: '质检类型'
};
//当前质检状态 0: 合格 1:不合格 2:让步接收 3:品质判定 4:返工 5:报废 6：特裁
modelField.QCStatus = {
    type: Number,
    Name: '质检状态'
};
//当前质检返工工序
modelField.QCReworkOperation = {
    type: Schema.ObjectId,
    ref: 'Operation',
    Name: '质检返工工序ID'
};
//返工次数
modelField.ReworkQty = {
    type: Number,
    Name: '返工次数'
};
//生产批号 
modelField.MOLotNumber = {
    type: String,
    trim: true,
    Name: '生产批号'
};
//出货批号 出货批次
modelField.ShipLotNumber = {
    type: String,
    trim: true,
    Name: '出货批号'
};
//生产订单
modelField.MO = {
    type: Schema.ObjectId,
    ref: 'MO',
    Name: '生产订单ID'
};
//生产订单编码
modelField.MOCode = {
    type: String,
    trim: true,
    Name: '生产订单编码'
};
//物料
modelField.ItemMaster = {
    type: Schema.ObjectId,
    ref: 'ItemMaster',
    Name: '物料ID'
};
//物料编码
modelField.ItemMasterCode = {
    type: String,
    trim: true,
    Name: '物料编码'
};
//物料名称
modelField.ItemMasterName = {
    type: String,
    trim: true,
    Name: '物料名称'
};
//物料规格
modelField.Specification = {
    type: String,
    default: '',
    trim: true,
    Name: '物料规格'
};

//完工计划
modelField.CompletePlan = {
    type: Schema.ObjectId,
    ref: 'CompletePlan',
    Name: '完工计划ID'
};

//已产生完工报告标识
modelField.IsERPComplete = {
    type: Boolean,
    Name: '有完工'
};
//报废标识
modelField.IsScrap = {
    type: Boolean,
    Name: '报废'
};
//打印次数
modelField.PrintQty = {
    type: Number,
    Name: '打印次数'
};

//扩展字段:
modelField.DescSeg1 = {
    type: String,
    default: '',
    trim: true,
    Name: '扩展字段1'
};
modelField.DescSeg2 = {
    type: String,
    default: '',
    trim: true,
    Name: '扩展字段2'
};
modelField.DescSeg3 = {
    type: String,
    default: '',
    trim: true,
    Name: '扩展字段3'
};

//2016-10-25 U9条码平台条码同步功能增加相关字段 -lwd
//条码ID
modelField.ErpID = {
    type: String,
    default: '',
    trim: true,
    Name: 'ErpID'
};

//条码类型 
modelField.ErpBCType = {
    type: Number,
    Name: '条码类型'
};

//条码类型：0.单据条码 1. 料品条码 2.容器条码
modelField.ErpBCTypeN = {
    type: String,
    default: '',
    trim: true,
    Name: '条码类型名称'
};
//实体Name
modelField.EntityName = {
    type: String,
    trim: true,
    Name: '实体名称'
};

//条码规则
modelField.BCRuleName = {
    type: String,
    default: '',
    trim: true,
    Name: '条码规则'
};
//数量类型名称 0.固定数量 1.单据数量 2.指定数量
modelField.QtyTypeN = {
    type: String,
    default: '',
    trim: true,
    Name: '数量类型名称'
};
//数量类型
modelField.Qty = {
    type: Number,
    Name: '数量类型'
};
//打印人
modelField.PrintPerson = {
    type : String,
    trim : true,
    Name: '打印人'
};

//是否打印
modelField.IsPrint = {
    type : Boolean ,
    Name: '打印'
};
 
//条码段1-20:
modelField.Segment1 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段1'
};
modelField.Segment2 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段2'
};
modelField.Segment3 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段3'
};
modelField.Segment4 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段4'
};
modelField.Segment5 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段5'
};
modelField.Segment6 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段6'
};
modelField.Segment7 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段7'
};
modelField.Segment8 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段8'
};
modelField.Segment9 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段9'
};
modelField.Segment10 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段10'
};
modelField.Segment11 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段11'
};
modelField.Segment12 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段12'
};
modelField.Segment13 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段13'
};
modelField.Segment14 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段14'
};
modelField.Segment15 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段15'
};
modelField.Segment16 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段16'
};
modelField.Segment17 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段17'
};
modelField.Segment18 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段18'
};
modelField.Segment19 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段19'
};
modelField.Segment20 = {
    type: String,
    default: '',
    trim: true,
    Name: '条码段20'
};

var newModel = new Model(modelField);
newModel.addIndex({Barcode: 1, QCStatus: 1});
newModel.create('BarcodeMaster', '条码主档');
